<?php

class wms_ctl_admin_lwdelivery extends desktop_controller
{
    /*
     * 修改物流费
     */
    public function updateDelivery()
    {
        $this->page('admin/print/updateDelivery.html');
    }

    /*
     * 保存
     */
    public function doUpdateDelivery()
    {
        $this->begin('');
        $delivery_bns = trim($_POST['delivery_bns']);
        $price = $_POST['price'];
        $bnArr = explode(',', $delivery_bns);
        //防止最后的逗号
        $deliveryBnArr = array();
        foreach ($bnArr as $key => $val) {
            if (!empty($val)) {
                $deliveryBnArr[] = $val;
            }
        }
        $wmsDeliveryObj = app::get('wms')->model('delivery');
        $omeDeliveryObj = app::get('ome')->model('delivery');
        $dataList = $wmsDeliveryObj->getList('delivery_id,delivery_bn,outer_delivery_bn', array('delivery_bn' => $deliveryBnArr));
        if (count($dataList) != count($deliveryBnArr)) {
            $this->end(false, '该编号中有不存在的！');
        }
        $outer_delivery_bnArr = array();
        foreach ($dataList as $key => $data) {
            $outer_delivery_bnArr[] = $data['outer_delivery_bn'];
        }
        $updateData['delivery_cost_expect'] = $price;
        $updateData['delivery_cost_actual'] = $price;
        $omeDeliveryObj->update($updateData, array('delivery_bn' => $outer_delivery_bnArr));
        $wmsDeliveryObj->update($updateData, array('delivery_bn' => $deliveryBnArr));
        $wmsLib=kernel::single('wms_receipt_delivery');
        foreach ($dataList as $key => $val) {
            $wmsLib->getFlatFee($val['delivery_id']);
        }

        $this->end(true, '修改成功');
    }




    /*
     * 修改物流费
     */
    public function updateOrder()
    {
        $this->page('admin/print/updateOrder.html');
    }


    /*
     * 保存
     */
    public function doUpdateOrder()
    {
        $this->begin('');
        $order_bns = trim($_POST['order_bns']);
        $price = $_POST['price'];
        $bnArr = explode(',', $order_bns);
        //防止最后的逗号
        $orderBnArr = array();
        foreach ($bnArr as $key => $val) {
            if (!empty($val)) {
                $orderBnArr[] = $val;
            }
        }
        $omeOrdersObj = app::get('ome')->model('orders');
        $dataList = $omeOrdersObj->getList('order_id', array('order_bn' => $orderBnArr));
        if (count($dataList) != count($orderBnArr)) {
            $this->end(false, '该订单编号中有不存在的！');
        }
        $updateData['payed'] = 1;
        $omeOrdersObj->update($updateData, array('order_bn' => $orderBnArr));
        $this->end(true, '修改成功');
    }





}